from django.shortcuts import render,HttpResponse
from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import ListModelMixin
from rest_framework import serializers
from rest_framework.response import Response
from anchor.models import AnchorInfo, AnchorDetail


class AnchorListSerializer(serializers.ModelSerializer):
    class Meta:
        model = AnchorInfo
        fields = '__all__'


class AnchorInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = AnchorDetail
        fields = '__all__'
        depth = 1


class AnchorView(GenericViewSet, ListModelMixin):
    queryset = AnchorInfo.objects.all()
    serializer_class = AnchorListSerializer

    def retrieve(self, request, *args, **kwargs):
        anchor_id = kwargs.get('pk')
        self.dispatch
        anchorinfo = AnchorDetail.objects.get(anchor_id=anchor_id)
        ser = AnchorInfoSerializer(instance=anchorinfo, many=False)
        return Response(ser.data)

